package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.JobStatus;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.AdminAbnormalLogistics;
import com.ygqh.baby.po.AdminUser;
import com.ygqh.baby.service.AdminAbnormalLogisticsService;
import com.ygqh.baby.shiro.utils.SessionUtil;

@Controller
@RequestMapping("/admin/abnormallogistics")
public class AbnormalLogisticsController extends BaseController<Object, java.lang.Long> {

	@Autowired
	private AdminAbnormalLogisticsService AdminAbnormalLogisticsService;

	@RequestMapping("addAbnormalLogistics")
	@ResponseBody
	public Message searchUser(String logisticsCode, String remark) {
		AdminUser user = SessionUtil.getCurrentUser();

		AdminAbnormalLogistics adminAbnormalLogistics = new AdminAbnormalLogistics(logisticsCode, remark, user.getTrueName());
		AdminAbnormalLogisticsService.save(adminAbnormalLogistics);
		return Message.success(null);
	}

	@RequestMapping("update")
	@ResponseBody
	public Message update(Long id, String resultMsg, String remark) {
		AdminUser user = SessionUtil.getCurrentUser();
		AdminAbnormalLogistics logistics = AdminAbnormalLogisticsService.findById(id);
		logistics.setResultMsg(resultMsg);
		logistics.setRemark(logistics.getRemark() + " " + remark);
		logistics.setUpdateBy(user.getTrueName());
		logistics.setUpdateTime(new Date());
		logistics.setJobStatus(JobStatus.Complete);
		AdminAbnormalLogisticsService.update(logistics);
		return Message.success(null);
	}

	@RequestMapping("search")
	@ResponseBody
	public Map<String, Object> search(String q, QueryInfo queryInfo, Date startDate, Date endDate, JobStatus jobStatus) {
		ResultSet<AdminAbnormalLogistics> resultSet = AdminAbnormalLogisticsService.search(queryInfo, q, jobStatus, startDate, endDate);
		return resultSet.toDatatables(null);
	}
}
